package UI;

import GestionBilleterie.Vendeur;
import UI_admin.Frame_administration;
import UI_vente.Frame_vente;
import javax.swing.JOptionPane;

/**
 *
 * @author Elsa Ferrare, Alexandre Becquet
 */
public class Frame_accueil extends javax.swing.JFrame {

    /** Creates new form Frame_accueil */
    public Frame_accueil() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonAdministration = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldLog = new javax.swing.JTextField();
        jButtonVente = new javax.swing.JButton();
        jTextFieldPassword = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButtonAdministration.setText("Administration");
        jButtonAdministration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdministrationActionPerformed(evt);
            }
        });

        jLabel1.setText("Log :");

        jLabel2.setText("Mot de passe :");

        jButtonVente.setText("Vente");
        jButtonVente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVenteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldLog)
                            .addComponent(jTextFieldPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(jButtonAdministration)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonVente)))
                .addContainerGap(123, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAdministration)
                    .addComponent(jButtonVente))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAdministrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdministrationActionPerformed
        Vendeur lAdmin=Vendeur.isAdmin(this.jTextFieldLog.getText(),this.jTextFieldPassword.getText());
        if(lAdmin!=null){
            new Frame_administration().setVisible(true);
            this.setVisible(false);
        }else{
            JOptionPane.showMessageDialog(this, "Erreur d'authentifiacation","",JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButtonAdministrationActionPerformed

    private void jButtonVenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVenteActionPerformed
        Vendeur leVendeur=Vendeur.isVendeur(this.jTextFieldLog.getText(),this.jTextFieldPassword.getText());
        if(leVendeur!=null){
            new Frame_vente(leVendeur,this).setVisible(true);
            this.setVisible(false);
        }else{
            JOptionPane.showMessageDialog(this, "Erreur d'authentifiacation","",JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButtonVenteActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frame_accueil().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdministration;
    private javax.swing.JButton jButtonVente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextFieldLog;
    private javax.swing.JPasswordField jTextFieldPassword;
    // End of variables declaration//GEN-END:variables

}
